Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to run spec files in random order #328

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AndyWalker-AMZN
Copy link

Because jasmine-node doesn't spin up a separate Node process for each spec file, it's possible for global state to get polluted in such a way that specs pass or fail depending on the order in which they're run.

For instance, a spec may accidentally omit the creation of some global config which is required for its class under test - but the spec might still run because a previous spec created the config. Obviously, the best way to deal with this is simply never to use global config, but that's not always practical.

One way to sniff out inadvertent order dependencies is to run spec files in a random order - similar to rspec's --order rand flag.

I wrote a relatively quick-and-dirty test order randomizer (attached to pull request) for my team's use, which has already succeeded in finding some inter-spec dependencies in our large set of Jasmine specs.

This adds the following options:

  • --randomize, which shuffles the list of spec files and prints out the seed it used to initialize the RNG
  • --seed SEED, which seeds the RNG to replay an earlier shuffled test run

Is this something that the jasmine-node project would be interested in? If so, I'm happy to massage it into commit-able shape, add tests etc.

This adds the following options:
  --randomize, which shuffles the list of spec files and
    prints out the seed it used to initialize the RNG
  --seed SEED, which seeds the RNG to replay an earlier
    shuffled test run
For the purposes of getting a test shuffler up and running quickly, I ended up
writing my own seedable array shuffler - however, this could be replaced by an existing NPM package if there is one, or moved into its own package.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant